using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Xml;
using System.Web;
using System.Web.Services;
using Dimok.Exceptions;
using Data;

namespace Dimok.Aspx.Manager.Administration
{
	/// <summary>
	/// Summary description for Administration.
	/// </summary>
	public class Administration : System.Web.Services.WebService
	{
		private UOX uox = new UOX();
		public Administration()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion

		#region Interviews
		[WebMethod]
		public void InterviewDoneBy_Update(int id,string fieldName,object fieldValue){
			try{
				SQL.UpdateField(uox.db,"SELECT * FROM "+SQL.InterviewDoneByTable+" WHERE ID="+id,fieldName,fieldValue);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public void InterviewDoneBy_Delete(int id){
			try{
				SQL.ExecuteNonQueryEx(uox.db,"DELETE FROM "+SQL.InterviewDoneByTable+" WHERE ID="+id);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public int InterviewDoneBy_Add(XmlElement xmlDataSet){
			try{
				DataTable dt = SQL.LoadDataTable(xmlDataSet);
				SQL.UpdateDataTable(dt,uox.db,"SELECT TOP 0 * FROM "+SQL.InterviewDoneByTable);	
				return Convert.ToInt32(dt.Rows[0][0]);
			}catch(Exception exc){ throw new ClientException(exc); }
		}

		[WebMethod]
		public void BorrowerInterview_Update(int id,string fieldName,object fieldValue){
			try{
				SQL.UpdateField(uox.db,"SELECT * FROM "+SQL.BorrowerInterviewTable+" WHERE Weight="+id,fieldName,fieldValue);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public void BorrowerInterview_Delete(int id){
			try{
				SQL.ExecuteNonQueryEx(uox.db,"DELETE FROM "+SQL.BorrowerInterviewTable+" WHERE Weight="+id);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public int BorrowerInterview_Add(XmlElement xmlDataSet){
			try{
				DataTable dt = SQL.LoadDataTable(xmlDataSet);
				SQL.UpdateDataTable(dt,uox.db,"SELECT TOP 0 * FROM "+SQL.BorrowerInterviewTable);	
				return Convert.ToInt32(dt.Rows[0][0]);
			}catch(Exception exc){ throw new ClientException(exc); }
		}

		[WebMethod]
		public void ReferenceInterview_Update(int id,string fieldName,object fieldValue){
			try{
				SQL.UpdateField(uox.db,"SELECT * FROM "+SQL.ReferenceInterviewTable+" WHERE Weight="+id,fieldName,fieldValue);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public void ReferenceInterview_Delete(int id){
			try{
				SQL.ExecuteNonQueryEx(uox.db,"DELETE FROM "+SQL.ReferenceInterviewTable+" WHERE Weight="+id);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public int ReferenceInterview_Add(XmlElement xmlDataSet){
			try{
				DataTable dt = SQL.LoadDataTable(xmlDataSet);
				SQL.UpdateDataTable(dt,uox.db,"SELECT TOP 0 * FROM "+SQL.ReferenceInterviewTable);	
				return Convert.ToInt32(dt.Rows[0][0]);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		#endregion

		#region Techician
		private const string TABLE_TECHICIAN = "t_Technician";
		[WebMethod]
		public void Technician_Update(int id,string fieldName,object fieldValue){
			try{
				SQL.UpdateField(uox.db,"SELECT * FROM "+TABLE_TECHICIAN+" WHERE ID="+id,fieldName,fieldValue);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public void Technician_Delete(int id){
			try{
				SQL.ExecuteNonQueryEx(uox.db,"DELETE FROM "+TABLE_TECHICIAN+" WHERE ID="+id);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		[WebMethod]
		public int Technician_Add(XmlElement xmlDataSet){
			try{
				DataTable dt = SQL.LoadDataTable(xmlDataSet);
				SQL.UpdateDataTable(dt,uox.db,"SELECT TOP 0 * FROM "+TABLE_TECHICIAN);	
				return (int)SQL.ExecuteScalarEx(
					uox.db,"SELECT ID FROM "+TABLE_TECHICIAN+" WHERE FirstName=@FN AND LastName=@LN",dt.Rows[0]["FirstName"],dt.Rows[0]["LastName"]);
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		#endregion

	}
}
